﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Services;

using com.vs.DataAccess;
using com.vs.DataAccess.DO;
using com.vs.General;

namespace com.vs.WebService
{
    /// <summary>
    /// Summary description for ManagementService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ManagementService : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetTransactionHisotries(string stSessID, string stCondXML)
        {
            List<KeyValuePair<string, KeyValuePair<string, object>>> dcCond = null;
            DataTable dt = null;
            Session sess = null;
            StringBuilder sbXML = null;

            try
            {
                sess = (Session)Application.Get(stSessID);
                if (null == sess)
                    return MessageManager.MSG_SES_001;
                dcCond = new List<KeyValuePair<string, KeyValuePair<string, object>>>();

                if (!StringManager.IsEmpty(stCondXML))
                {
                    dcCond = XMLDocManager.BuildQueryCondition(stCondXML);
                }


                dt = TransactionHistoryDO.GetTableByColumns(sess, dcCond, null);
                if (DataManager.IsEmpty(dt))
                    return null;
                sbXML = new StringBuilder();
                dt.TableName = "TRANSACTION_HISTORY";
                dt.DataSet.DataSetName = "TRANSACTION_HISTORIES";
                dt.DataSet.WriteXml(new StringWriter(sbXML));
                //return XMLDocManager.TransformStringWithFile(sbXML.ToString(), XSLT_DIR + "ItemLookUp.xslt", Encoding.UTF8);
                return sbXML.ToString();

            }
            catch (Exception e)
            {
                return MessageManager.MSG_GEN_000 + e.Message;
            }
            finally
            {
            }
        }

        [WebMethod]
        public string GetProcessHisotries(string stSessID, string stCondXML)
        {
            List<KeyValuePair<string, KeyValuePair<string, object>>> dcCond = null;
            DataTable dt = null;
            Session sess = null;
            StringBuilder sbXML = null;

            try
            {
                sess = (Session)Application.Get(stSessID);
                if (null == sess)
                    return MessageManager.MSG_SES_001;
                dcCond = new List<KeyValuePair<string, KeyValuePair<string, object>>>();

                if (!StringManager.IsEmpty(stCondXML))
                {
                    dcCond = XMLDocManager.BuildQueryCondition(stCondXML);
                }


                dt = ProcessHistoryDO.GetTableByColumns(sess, dcCond, null);
                if (DataManager.IsEmpty(dt))
                    return null;
                sbXML = new StringBuilder();
                dt.TableName = "PROCESS_HISTORY";
                dt.DataSet.DataSetName = "PROCESS_HISTORIES";
                dt.DataSet.WriteXml(new StringWriter(sbXML));
                //return XMLDocManager.TransformStringWithFile(sbXML.ToString(), XSLT_DIR + "ItemLookUp.xslt", Encoding.UTF8);
                return sbXML.ToString();

            }
            catch (Exception e)
            {
                return MessageManager.MSG_GEN_000 + e.Message;
            }
            finally
            {
            }
        }

    }
}
